﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Labirinto_Magico
{
    public struct TextureData
    {
        public Texture2D winnerTexture;
        public Texture2D arrow;
        public Texture2D arrowSelected;
        public Texture2D newGame;
        public Texture2D newGameSelected;
        public Texture2D loadGame;
        public Texture2D loadGameSelected;
        public Texture2D tutorial;
        public Texture2D tutorialSelected;
        public Texture2D saveGame;
        public Texture2D saveGameSelected;
        public Texture2D exit;
        public Texture2D exitSelected;
        public Texture2D resume;
        public Texture2D resumeSelected;
        public Texture2D mainMenu;
        public Texture2D mainMenuSelected;
        public Texture2D rotate;
        public Texture2D rotateSelected;

        public Texture2D streightTile;
        public Texture2D curvedTile;
        public Texture2D tieTile;

        public Texture2D playerBlue;
        public Texture2D playerRed;
        public Texture2D playerGreen;

        public Texture2D playerScore;
        
        public Texture2D pause;
        public Texture2D pauseSelected;
        
        public Texture2D mouse;
        public Texture2D background;
        public Texture2D loadingPointer;
        public Texture2D title;

        public SpriteFont victoryFont;
        public SpriteFont scoreFont;
    }

    public class RenderingData
    {
        public TextureData mTextureData;

        public SpriteBatch spriteBatch  = null;
        public GraphicsDevice graphics  = null;

        static Vector2 mScale = new Vector2(1f, 1f);

        public void Load(GraphicsDevice gd, ContentManager content)
        {
            mTextureData.streightTile = content.Load<Texture2D>("Tile/streightTile");
            mTextureData.curvedTile = content.Load<Texture2D>("Tile/curvedTile");
            mTextureData.tieTile = content.Load<Texture2D>("Tile/tieTile");

            mTextureData.victoryFont = content.Load<SpriteFont>("Font/font");
            mTextureData.scoreFont = content.Load<SpriteFont>("Font/scoreFont");

            mTextureData.exit = content.Load<Texture2D>("Main Menu/Exit (1)");
            mTextureData.exitSelected = content.Load<Texture2D>("Main Menu/Exit (5)");
            mTextureData.loadGame = content.Load<Texture2D>("Main Menu/Load game3");
            mTextureData.loadGameSelected = content.Load<Texture2D>("Main Menu/Load game2");
            mTextureData.mainMenu = content.Load<Texture2D>("Pause Menu/Main menu3");
            mTextureData.mainMenuSelected = content.Load<Texture2D>("Pause Menu/Main menu2");
            mTextureData.newGame = content.Load<Texture2D>("Main Menu/New game3");
            mTextureData.newGameSelected = content.Load<Texture2D>("Main Menu/New game2");
            mTextureData.resume = content.Load<Texture2D>("Pause Menu/Resume3");
            mTextureData.resumeSelected = content.Load<Texture2D>("Pause Menu/Resume2");
            mTextureData.saveGame = content.Load<Texture2D>("Pause Menu/Save game3");
            mTextureData.saveGameSelected = content.Load<Texture2D>("Pause Menu/Save game2");
            mTextureData.tutorial = content.Load<Texture2D>("Main Menu/Tutorial3");
            mTextureData.tutorialSelected = content.Load<Texture2D>("Main Menu/Tutorial2");
            mTextureData.winnerTexture = content.Load<Texture2D>("GUI/pergamena");
            mTextureData.arrow = content.Load<Texture2D>("GUI/arrow");
            mTextureData.arrowSelected = content.Load<Texture2D>("GUI/arrowSelected");
            mTextureData.rotate = content.Load<Texture2D>("GUI/Rotate");
            mTextureData.rotateSelected = content.Load<Texture2D>("GUI/Rotate2");
            mTextureData.playerBlue = content.Load<Texture2D>("Players/blueMerlin");
            mTextureData.playerRed = content.Load<Texture2D>("Players/redMerlin");
            mTextureData.playerGreen = content.Load<Texture2D>("Players/greenMerlin");
            mTextureData.pause = content.Load<Texture2D>("GUI/Pause3");
            mTextureData.pauseSelected = content.Load<Texture2D>("GUI/Pause2");

            mTextureData.background = content.Load<Texture2D>("Sfondo");
            mTextureData.playerScore = content.Load<Texture2D>("GUI/score");
            mTextureData.title = content.Load<Texture2D>("Main Menu/title");


            graphics        = gd;

            spriteBatch = new SpriteBatch(gd);
        }

        public void DrawTexture(Texture2D iTexture, Vector2 iDim, Vector2 iCenterPos, float rotation, Color color)
        {
            Vector2 scale = new Vector2(
                iDim.X / iTexture.Width,
                iDim.Y / iTexture.Height);

            spriteBatch.Begin();
            spriteBatch.Draw(
                iTexture,
                iCenterPos,
                null,
                color,
                rotation,
                new Vector2(iTexture.Width * 0.5f, iTexture.Height * 0.5f),
                scale,
                SpriteEffects.None,
                0);
            spriteBatch.End();
        }

        public void DrawFont(SpriteFont iFont, Vector2 iPosition, String iPhrase, Color iColor, float iScale)
        {
            spriteBatch.Begin();

            var string_size = mTextureData.victoryFont.MeasureString(iPhrase);
            spriteBatch.DrawString(
                iFont,
                iPhrase,
                iPosition,
                iColor,
                0,
                new Vector2(string_size.X * 0.5f, string_size.Y * 0.5f),
                iScale,
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }

        public void DrawBackground()
        {
            spriteBatch.Begin();
            spriteBatch.Draw(mTextureData.background, Vector2.Zero, Color.White);
            spriteBatch.End();
        }
    }
}
